import request from '@/utils/request'
import { PageDate } from '@/model'
import { EnvironmentDTO } from '@/model/efficient/EnvironmentDTO'
import { EnvironmentServerDTO } from '@/model/efficient/EnvironmentServerDTO'
import { EnvironmentSetServerDTO } from '@/model/efficient/EnvironmentSetServerDTO'

/**
 *
 * @param data
 * @returns
 */
export function environmentPage(params): Promise<PageDate<EnvironmentDTO>> {
  return request.get('/api/efficient/environment/page', params)
}

export function environmentRemove(id: number) {
  return request.delete(`/api/efficient/environment/${id}`)
}

export function environmentSave(data: EnvironmentDTO) {
  return request.post('/api/efficient/environment', data)
}

export function environmentUpdate(data: EnvironmentDTO) {
  return request.put(`/api/efficient/environment/${data.id}`, data)
}

/**
 * 获取环境所有服务器
 * @param data
 */
export function getEnvironmentServer(environmentId: number): Promise<Array<EnvironmentServerDTO>> {
  return request.get(`/api/efficient/environment/getByEnvironmentId/${environmentId}`)
}

/**
 * 设置服务器
 * @param data
 */
export function setEnvironmentServer(data: EnvironmentSetServerDTO) {
  return request.post(`/api/efficient/environment/setServer/${data.environmentId}`, data)
}

/**
 * 获取所有环境
 * @param data
 */
export function getAllEnvironment(): Promise<Array<EnvironmentDTO>> {
  return request.get('/api/efficient/environment/getAll')
}
